<template>
  <div>
    <el-breadcrumb class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/main' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>职位中心</el-breadcrumb-item>
    </el-breadcrumb>

    <el-tabs v-model="activeName" @tab-click="handleClick">
      <el-tab-pane label="已审核职位" name="first">
        <el-form :inline="true" v-model="position" class="demo-form-inline" style="margin-top: 20px">

          <el-form-item label="公司名称">
            <el-input v-model="position.companyName" placeholder="地址"></el-input>
          </el-form-item>
          <el-form-item label="职位名称">
            <el-input v-model="position.positionName" placeholder="职位名称"></el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="getPositionListChecked()">查询</el-button>
          </el-form-item>

          <el-table
                  v-loading="loading"
                  :data="pageInfo.list"
                  style="width: 100%"
                  :stripe=true
                  :border=true
                  height="450">
            <el-table-column type="expand">
              <template slot-scope="props">
                <el-form label-position="left" inline class="demo-table-expand">
                  <el-form-item label="福利">
                    <span>：{{ props.row.welfare }}； </span>
                  </el-form-item>
                  <el-form-item label="点击量">
                    <span>：{{ props.row.lookNums }}； </span>
                  </el-form-item>
                  <el-form-item label="城市">
                    <span>：{{ props.row.city }}； </span>
                  </el-form-item>
                  <el-form-item label="工作经验">
                    <span>：{{ props.row.workExp }}； </span>
                  </el-form-item>
                  <el-form-item label="职位描述">
                    <span>：{{ props.row.workDescription }}</span>
                  </el-form-item>
                </el-form>
              </template>
            </el-table-column>
            <el-table-column
                    prop="companyName"
                    label="公司名称"
                    width="350">
            </el-table-column>
            <el-table-column
                    prop="hrName"
                    label="发布人"
                    width="120">
            </el-table-column>
            <el-table-column
                    prop="positionName"
                    label="职位名称"
                    width="140">
            </el-table-column>
            <el-table-column
                    prop="eduRequirements"
                    label="学历要求"
                    width="120">
            </el-table-column>
            <el-table-column
                    label="薪资范围"
                    width="120">
              <template slot-scope="scope">
                <span>{{scope.row.minSalary}}K-{{scope.row.maxSalary}}K</span>
              </template>
            </el-table-column>
            <el-table-column
                    label="创建时间"
                    width="120">
              <template slot-scope="scope">
                <span>{{makeSimpleDate(scope.row.createTime)}}</span>
              </template>
            </el-table-column>
            <el-table-column
                    label="修改时间"
                    width="120">
              <template slot-scope="scope">
                <span>{{makeSimpleDate(scope.row.updateTime)}}</span>
              </template>
            </el-table-column>
            <el-table-column
                    prop="jobclassify"
                    label="工作分类"
                    width="120">
            </el-table-column>

            <el-table-column
                    label="删除状态"
                    width="100">
              <template slot-scope="scope">
                <el-tag v-if="scope.row.isdeleted==0" type="info">未删除</el-tag>
                <el-tag v-else type="danger">已删除</el-tag>
              </template>
            </el-table-column>

            <el-table-column
                    label="上线状态"
                    width="120">
              <template slot-scope="scope">
                <el-tag v-if=" (scope.row.isdeleted==1)|| (scope.row.isOpen==0) ||(scope.row.ischeck!=1)" type="danger">已下线</el-tag>
                <el-tag v-else type="success">已上线</el-tag>
              </template>
            </el-table-column>

            <el-table-column label="审核失败/通过审核"  fixed="right">
              <template slot-scope="scope">
                <el-switch
                        @change="changeCheck($event,scope.row.positionId)"
                        v-model="scope.row.ischeck"
                        :inactive-value="2"
                        :active-value="1"
                        active-color="#13ce66"
                        inactive-color="#ff4949">
                </el-switch>
              </template>
            </el-table-column>
          </el-table>
        </el-form>
        <div style="float: right">
          <el-pagination
                  background
                  layout="prev, pager, next"
                  :total="pageInfo.total"
                  :page-size="pageInfo.pageSize"
                  @current-change="handlePage1"
          >
          </el-pagination>
        </div>
      </el-tab-pane>

      <el-tab-pane label="待审核职位" name="two">
        <el-form :inline="true" v-model="position2" class="demo-form-inline" style="margin-top: 20px">
          <el-form-item label="公司名称">
            <el-input v-model="position2.companyName" placeholder="地址"></el-input>
          </el-form-item>
          <el-form-item label="职位名称">
            <el-input v-model="position2.positionName" placeholder="职位名称"></el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="getPositionListNoChecked()">查询</el-button>
          </el-form-item>

          <el-table
                  v-loading="loading"
                  :data="pageInfo2.list"
                  style="width: 100%"
                  :stripe=true
                  :border=true
                  height="450">
            <el-table-column type="expand">
              <template slot-scope="props">
                <el-form label-position="left" inline class="demo-table-expand">
                  <el-form-item label="福利">
                    <span>：{{ props.row.welfare }}； </span>
                  </el-form-item>
                  <el-form-item label="点击量">
                    <span>：{{ props.row.lookNums }}； </span>
                  </el-form-item>
                  <el-form-item label="城市">
                    <span>：{{ props.row.city }}； </span>
                  </el-form-item>
                  <el-form-item label="工作经验">
                    <span>：{{ props.row.workExp }}； </span>
                  </el-form-item>
                  <el-form-item label="职位描述">
                    <span>：{{ props.row.workDescription }}</span>
                  </el-form-item>
                </el-form>
              </template>
            </el-table-column>
            <el-table-column
                    prop="companyName"
                    label="公司名称"
                    width="350">
            </el-table-column>
            <el-table-column
                    prop="hrName"
                    label="发布人"
                    width="80">
            </el-table-column>
            <el-table-column
                    prop="positionName"
                    label="职位名称"
                    width="220">
            </el-table-column>
            <el-table-column
                    prop="eduRequirements"
                    label="学历要求"
                    width="80">
            </el-table-column>
            <el-table-column
                    label="薪资范围"
                    width="120">
              <template slot-scope="scope">
                <span>{{scope.row.minSalary}}K-{{scope.row.maxSalary}}K</span>
              </template>
            </el-table-column>
            <el-table-column
                    label="创建时间"
                    width="120">
              <template slot-scope="scope">
                <span>{{makeSimpleDate(scope.row.createTime)}}</span>
              </template>
            </el-table-column>
            <el-table-column
                    label="修改时间"
                    width="120">
              <template slot-scope="scope">
                <span>{{makeSimpleDate(scope.row.updateTime)}}</span>
              </template>
            </el-table-column>
            <el-table-column
                    prop="jobclassify"
                    label="工作分类"
                    width="120">
            </el-table-column>

            <el-table-column
                    label="删除状态"
                    width="120">
              <template slot-scope="scope">
                <el-tag v-if="scope.row.isdeleted==0" type="success">未删除</el-tag>
                <el-tag v-else type="danger">已删除</el-tag>
              </template>
            </el-table-column>


            <el-table-column label="操作"  fixed="right" width="120">
              <template slot-scope="scope">
                <el-button type="success" round
                           icon="el-icon-check"
                           size="mini"
                           @click="passCheck(scope.row.positionId)"
                ></el-button>
                <el-button type="danger" round
                           icon="el-icon-close"
                           size="mini"
                           @click="noCheck(scope.row.positionId)"
                ></el-button>
              </template>
            </el-table-column>
          </el-table>
        </el-form>
        <div style="float: right">
          <el-pagination
                  background
                  layout="prev, pager, next"
                  :total="pageInfo2.total"
                  :page-size="pageInfo2.pageSize"
                  @current-change="handlePage2"
          >
          </el-pagination>
        </div>
      </el-tab-pane>
    </el-tabs>

  </div>
</template>

<script>
  import {makeSimpleDate, makeDate} from "../../../common/js/dateformat"

  export default {
    name: "admin-position",
    data() {
      return {
        loading: false,
        pageIndex: 1,
        pageIndex2: 1,
        position: {
          companyName:'',
          positionName:'',
        },
        position2:{
          companyName:'',
          positionName:'',
          ischeck:0,
        },
        pageInfo: {},
        pageInfo2: {},
      }
    },
    created() {
      this.getPositionListChecked();
      this.getPositionListNoChecked();

    },
    methods: {
      getPositionListChecked(){
        this.loading=true;
        this.$ajax.post(this.$config.url + `position/adminSelPositionCheck/${this.pageIndex}`,this.position
        ).then(res => {
          this.pageInfo = res.data;
          this.loading = false;
        }).finally(() => {
        })
      },
      getPositionListNoChecked(){
        this.loading=true;
        this.$ajax.post(this.$config.url + `position/selectPosition/${this.pageIndex2}`,this.position2
        ).then(res => {
          this.pageInfo2 = res.data;
          this.loading = false;
        }).finally(() => {
        })
      },
      passCheck(positionId){
        this.$ajax.post(this.$config.url + `admin/position/updatePositionCheck`,{
            "positionId":positionId,
            "ischeck":1,
            }
        ).then(res => {
          if(res.data==true){
            this.$message.success("操作成功")
          }else{
            this.$message.error("出错了，操作失败")
          }
          //刷新一下
          this.getPositionListNoChecked();
          this.getPositionListNoChecked();
        }).finally(() => {
        })
      },
      noCheck(positionId){
        this.$ajax.post(this.$config.url + `admin/position/updatePositionCheck`,{
              "positionId":positionId,
              "ischeck":2,
            }
        ).then(res => {
          if(res.data==true){
            this.$message.success("操作成功")
          }else{
            this.$message.error("出错了，操作失败")
          }
          //刷新一下
          this.getPositionListNoChecked();
          this.getPositionListNoChecked();
        }).finally(() => {
        })
      },
      changeCheck($event,positionId){

        this.$ajax.post(this.$config.url + `admin/position/updatePositionCheck`,{
          "positionId":positionId,
          "ischeck":$event,
            }
        ).then(res => {
          if(res.data==true){
            this.$message.success("操作成功")
          }else{
            this.$message.error("出错了，操作失败")
          }
          //刷新一下
          this.getPositionListChecked();
        }).finally(() => {
        })
      },
      handlePage1(val){
        console.log(val)
        this.pageIndex = val;
        //加载数据
        this.getPositionListChecked()
      },
      handlePage2(val){
        console.log(val)
        this.pageIndex2 = val;
        //加载数据
        this.getPositionListNoChecked()
      },
      makeSimpleDate(date) {
        return makeSimpleDate(date)
      },
      makeDate(date){
        return makeDate(date)
      },

    }
  }
</script>

<style scoped>

</style>